package logger

import (
	"github.com/sirupsen/logrus"
	"sync"
)

var once sync.Once
var Log Logger

type Logger interface {
	Trace(args ...interface{})
	Tracef(format string, args ...interface{})

	Debug(args ...interface{})
	Debugf(format string, args ...interface{})

	Info(args ...interface{})
	Infof(format string, args ...interface{})

	Warn(args ...interface{})
	Warnf(format string, args ...interface{})

	Error(args ...interface{})
	Errorf(format string, args ...interface{})

	Fatal(args ...interface{})
	Fatalf(format string, args ...interface{})
}

type LevelReloadable interface {
	ReloadRootLevel(level logrus.Level)
}

func Trace(args ...interface{}) {
	Log.Trace(args)
}
func Tracef(format string, args ...interface{}) {
	Log.Tracef(format, args)
}
func Debug(args ...interface{}) {
	Log.Debug(args)
}
func Debugf(format string, args ...interface{}) {
	Log.Debugf(format, args)
}
func Info(args ...interface{}) {
	Log.Info(args)
}
func Infof(format string, args ...interface{}) {
	Log.Infof(format, args)
}
func Warn(args ...interface{}) {
	Log.Warn(args)
}
func Warnf(format string, args ...interface{}) {
	Log.Warnf(format, args)
}
func Error(args ...interface{}) {
	Log.Error(args)
}
func Errorf(format string, args ...interface{}) {
	Log.Errorf(format, args)
}
func Fatal(args ...interface{}) {
	Log.Error(args)
}
func Fatalf(format string, args ...interface{}) {
	Log.Fatalf(format, args)
}

func ReloadRootLevel(level logrus.Level) {
	Log.(LevelReloadable).ReloadRootLevel(level)
}

func initialization(l Logger) {
	once.Do(func() {
		Log = l
	})
}
